﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="profile.aspx.cs" Inherits="DeansWsccProject.profile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:DetailsView ID="profileDetailsView" runat="server" AutoGenerateRows="False" DataKeyNames="ID">
        <Fields>
            <asp:TemplateField>
                <HeaderTemplate>
                    <img class="profileImage" src="/<%# Eval("Picture") %>" alt="Profile image not available" />
                </HeaderTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <%# Eval("FirstName") %> <%# Eval("LastName") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="profileUserName" HeaderText="UserName" ControlStyle-CssClass="username" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ControlStyle-CssClass="description" />
        </Fields>
    </asp:DetailsView>
    <asp:Button ID="btnEditProfile" runat="server" Text="Edit Profile" PostBackUrl="~/edit-profile.aspx" />
    <ajaxToolkit:RoundedCornersExtender ID="btnEditProfile_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="btnEditProfile">
    </ajaxToolkit:RoundedCornersExtender>
    <br />

    <asp:PlaceHolder ID="collaborationsStartedPlaceHolder" runat="server">
    <h3>eBook Collaborations Started</h3>
    <asp:GridView ID="collaborationsStartedGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowDataBound="collaborationsStartedGridView_RowDataBound" Width="700px">
        <Columns>
            <asp:BoundField DataField="description" HeaderText="Posts" />
            <asp:TemplateField HeaderText="Collaborators">
                <ItemTemplate>
                    <asp:Repeater ID="acceptedCollaboratorsRepeater" runat="server">
                        <ItemTemplate>
                            <a href="/profile.aspx?profileUserName=<%# DataBinder.Eval(Container.DataItem, "profileUserName") %>"><%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %></a>, 
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Collaboration Requests">
                <ItemTemplate>
                    <asp:Repeater ID="requestedCollaboratorsRepeater" runat="server">
                        <ItemTemplate>
                            <a href="/profile.aspx?profileUserName=<%# DataBinder.Eval(Container.DataItem, "profileUserName") %>"><%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %></a>
                            <asp:Button ID="btnAcceptCollaboratorRequest" runat="server" Text="Accept Request" OnClick="btnAcceptCollaboratorRequest_Click" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID" ) + ";" + DataBinder.Eval(Container.DataItem, "profileUserName") %>' />
                            <ajaxToolkit:RoundedCornersExtender ID="btnAcceptCollaboratorRequest_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="btnAcceptCollaboratorRequest">
                            </ajaxToolkit:RoundedCornersExtender>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                    <asp:Button ID="btnSendCollaboratorRequest" runat="server" Text="Send Collaboration Request" OnClick="btnSendCollaboratorRequest_Click" CommandArgument='<%# Eval("ID") %>' />
                    <ajaxToolkit:RoundedCornersExtender ID="btnSendCollaboratorRequest_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="btnSendCollaboratorRequest">
                    </ajaxToolkit:RoundedCornersExtender>
                    <asp:Button ID="btnCollaboratorRequestSent" runat="server" Text="Collaborator Request Sent" Enabled="False" />
                    <ajaxToolkit:RoundedCornersExtender ID="btnCollaboratorRequestSent_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="btnCollaboratorRequestSent">
                    </ajaxToolkit:RoundedCornersExtender>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="collaborationsJoinedPlaceHolder" runat="server">
        <h3>eBook Collaborations Joined</h3>
    <asp:GridView ID="collaborationsJoinedGridView" runat="server" AutoGenerateColumns="False" DataSourceID="collaborationsJoinedSqlDataSource" DataKeyNames="ID" OnRowDataBound="collaborationsJoinedGridView_RowDataBound" Width="700px">
        <Columns>
            <asp:BoundField DataField="description" HeaderText="Posts" />
            <asp:HyperLinkField HeaderText="Started by" DataNavigateUrlFields="originalPoster" DataNavigateUrlFormatString="/profile.aspx?profileUserName={0}" DataTextField="originalPoster" />
            <asp:TemplateField HeaderText="Collaborators">
                <ItemTemplate> 
                    <asp:Repeater ID="collaboratorsJoinedRepeater" runat="server">
                        <ItemTemplate>
                            <a href="/profile.aspx?profileUserName=<%# DataBinder.Eval(Container.DataItem, "profileUserName") %>"><%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %></a>, 
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </asp:PlaceHolder>
    <asp:SqlDataSource ID="collaborationsJoinedSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" SelectCommand="SELECT [ID], [description], [originalPoster], [profileUserName], [state] FROM [userCollaborationsView] WHERE (([profileUserName] = ?) AND ([state] = ?)) ORDER BY [ID] DESC">
        <SelectParameters>
            <asp:QueryStringParameter Name="profileUserName" QueryStringField="profileUserName" Type="String" />
            <asp:Parameter DefaultValue="requestAccepted" Name="state" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:PlaceHolder ID="publishedEBooksPlaceHolder" runat="server">
        <h3>My Published eBooks</h3>
    </asp:PlaceHolder>
    <asp:GridView ID="authoredEBooksGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="authoredEBooksGridViewSqlDataSource" AllowSorting="True">
        <Columns>
            <asp:TemplateField SortExpression="eBookTitle" ItemStyle-HorizontalAlign="Center" HeaderText="Title of eBook">
                <ItemTemplate>
                    <a href="/details.aspx?ID=<%# Eval("ID") %>"><img class="eBookImage" src="/<%# Eval("eBookImage") %>" alt="<%# Eval("eBookTitle") %> image not available" /></a>
                    <br />
                    <a class='eBookTitle' href='/details.aspx?ID=<%# Eval("ID") %>'><%# Eval("eBookTitle") %></a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Rating" SortExpression="eBookRating">
                <ItemTemplate>
                    <%# DeansWsccProject.App_Code.functions.getRating(Convert.ToString(Eval("eBookRating"))) %>

                    <!-- Show no. reviews link only if eBook has been rated at least once -->
                    <span id="Span1" runat='server' Visible='<%# Convert.ToString(Eval("eBookRating")) != "" %>'>
                        <br />
                        <a href='/details.aspx?ID=<%# Eval("ID") %>#recent-reviews'>(<%# DeansWsccProject.App_Code.functions.getNoReviews(Convert.ToString(Eval("ID"))) %>Reviews)</a>
                    </span>

                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Released" SortExpression="eBookReleaseDate">
                <ItemTemplate>
                    <%# Convert.ToString(Eval("eBookReleaseDate")).Remove(10, 9) %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="details.aspx?ID={0}" HeaderText="More Details" Text="View More" >
                <ControlStyle CssClass="eBookViewDetails" />
            </asp:HyperLinkField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="authoredEBooksGridViewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [ID], [eBookTitle], [eBookImage], [eBookReleaseDate], [eBookRating] FROM [eBookAuthorView] WHERE ([profileUserName] = ?) ORDER BY [eBookReleaseDate], [eBookTitle]">
        <SelectParameters>
            <asp:QueryStringParameter Name="profileUserName" QueryStringField="profileUserName" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
